{extend name="layout/base"}
{block name="title"}管理员修改{/block}
{block name="main"}
<div class="right-main">
    <div class="mdui-card border-1 mdui-shadow-0 mdui-m-b-2 ">
        <div class="mdui-card-primary">
            <h3>用户修改</h3>
        </div>
        <div class="mdui-divider "></div>
        <div class="mdui-card-content">
            <form action="" class="layui-form ">
                <div class="mdui-textfield mdui-p-l-2">
                    <div class="mdui-textfield-label">用户名</div>
                    <input disabled value="{$admin.username}" name="username" class="mdui-textfield-input" type="text"/>
                </div>
                <div class="mdui-textfield mdui-p-l-2">
                    <div class="mdui-textfield-label">密码</div>
                    <input name="password" class="mdui-textfield-input" type="password">
                </div>
                <div class="mdui-textfield mdui-p-l-2">
                    <div class="mdui-textfield-label mdui-m-b-1">是否禁用</div>
                    <input type="checkbox" value="0" name="status" lay-text="开启|关闭" lay-skin="switch" {if $admin.status eq 0} checked {/if}>
                </div>
                <div class="mdui-textfield mdui-p-l-2">
                    <div class="mdui-textfield-label mdui-m-b-1">超级管理员权限</div>
                    <input type="checkbox" value="1" name="super" lay-text="开启|关闭" lay-skin="switch" {if $admin.super eq 1}checked{/if}>
                </div>
                <div class="mdui-textfield mdui-p-l-2">
                    <button class="mdui-btn border-1" lay-submit lay-filter="submit">提交</button>
                </div>
                <input type="hidden" name="_method" value="PUT">
            </form>
        </div>

    </div>
</div>
{/block}
{block name="script"}
<script>
    layui.use('form', function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.jquery;
        form.on('submit(submit)', function (data) {
            $.post('/admin/user/{$admin.id}', data.field, function (res) {

                if (res.code === 1) {
                    layer.msg(res.msg, {icon: 6, time: 1500}, () => {
                        layer.load({
                            shade: 0.5,
                            time: 0,
                        });
                        location.href = res.url
                    })
                } else {
                    layer.msg(res.msg, {icon: 5, anim: 2, time: 1500}, () => {
                        // location.reload()
                    })
                }
            })
            return false;
        });
    });
</script>
{/block}
